import Vue from "vue";
import Vuex from "vuex";
import userApi from "../api/user.js"
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    token:"",
  },
  mutations: {
    login(state,token){
      state.token = token
    }
  },
  actions: {
    user({commit},form){
      return new Promise((resolve,reject)=>{
        userApi.login(form.username.trim(),form.password.trim()).then(response=>{
          // console.log(response);
          resolve(response)
          commit("login",response.data.data.token)
        }).catch(error=>{
          reject(error)
        })
      })
    }
  },
  modules: {},
});
